package com.mo2323.merchant.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.mo2323.common.dbo.StatPageInfo;
import com.mo2323.common.util.AjaxObject;
import com.mo2323.common.util.Page;
import com.mo2323.service.merchant.ICustomerService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @author xjw
 * @date 2019/1/23 - 16:20
 */
@Controller
@RequestMapping("/customer")
public class CustomerController extends BaseController {

    @Reference
    private ICustomerService customerService;

    @RequestMapping(value = "/analysisList", method ={RequestMethod.POST, RequestMethod.GET} )
    @ResponseBody
    public AjaxObject getAnalysisList(@RequestParam int vid, @RequestParam int type,
                                   @RequestParam(value = "page", defaultValue = "1", required = false) int page,
                                   @RequestParam(value = "rows", defaultValue = "10", required = false) int rows) {
        try{
            Page pageDefine = new Page();
            pageDefine.setPage(page);
            pageDefine.setRows(rows);

            StatPageInfo<Map<String, Object>> pageInfo = customerService.getCustomerListByType(vid, type,pageDefine);
            return AjaxObject.ok().put("data", pageInfo);
        } catch (Exception e){
            logger.error("getAnalysisList Exception：", e);
            return AjaxObject.error("getAnalysisList Exception：" + e.getMessage());
        }
    }


}
